package com.lx.oms.controller.manager.impl;

import java.math.BigInteger;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lx.oms.common.constant.SystemConstant.StatusType;
import com.lx.oms.common.entity.Page;
import com.lx.oms.common.entity.Query;
import com.lx.oms.common.utils.Utils;
import com.lx.oms.controller.dao.UserMapper;
import com.lx.oms.controller.entity.UserEntity;
import com.lx.oms.controller.manager.UserManager;

/**
 * 用户表
 *
 * @author houzhong
 * @date 2018年7月10日 上午9:24:32
 */
@Component("userManager")
public class UserManagerImpl implements UserManager {

	@Autowired
	private UserMapper userMapper;
	

	@Override
	public List<UserEntity> listUser(Page<UserEntity> page, Query search) {
		return userMapper.listForPage(page, search);
	}

	@Override
	public int saveUser(UserEntity user) {
		if (user.getId() == null) {
			user.setId(Utils.id().toString());
		}
		return userMapper.save(user);
	}

	@Override
	public UserEntity getUserById(BigInteger id) {
		UserEntity tUser = userMapper.getObjectById(id);
		return tUser;
	}

	@Override
	public int updateUser(UserEntity user) {
		return userMapper.update(user);
	}

	@Override
	public int batchRemove(String[] id) {
		int count = userMapper.batchRemove(id);
		return count;
	}

	@Override
	public int updateUserEnable(String[] id) {
		Query query = new Query();
		query.put("status", StatusType.ENABLE.getValue());
		query.put("id", id);
		int count = userMapper.updateUserStatus(query);
		return count;
	}

	@Override
	public int updateUserDisable(String[] id) {
		Query query = new Query();
		query.put("status", StatusType.DISABLE.getValue());
		query.put("id", id);
		int count = userMapper.updateUserStatus(query);
		return count;
	}
	
}
